import { defineStore } from "pinia";

export const useAuthStore = defineStore({
    id: "auth",
    state: () => {
        return {
            token: undefined,
            userProfile: undefined,
        };
    },
    getters: {
    },
    actions: {
        authenticate(data) {
            this.token = data.token;
        },
        setUserProfile(userProfile) {
            this.userProfile = userProfile;
        },
        unAuthenticate() {
            this.token = undefined;
            this.userProfile = undefined;
        }
    },
    // 开启认证信息持久化存储，保存在sessionStorage，浏览器窗口关闭后清空
    persist: {
        key: "fast_alden_auth",
        storage: sessionStorage,
    }
});

export default useAuthStore;